package com.atguigu.srb.mq.service;

import com.alibaba.fastjson.JSON;
import com.atguigu.srb.base.dto.SmsDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MqService {
    //发送mq消息的业务方法
    @Autowired
    RabbitTemplate rabbitTemplate;

    public void sendMsg(String exchange , String routingkey, SmsDTO msg){
        log.info("发送mq消息：exchange={},routingkey={},msg={}",exchange,routingkey,
                JSON.toJSONString(msg));
        rabbitTemplate.convertAndSend(exchange,routingkey,msg);
    }
}
